package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;


    @Autowired
    private TbClueMapper clueMapper;
    /**
     * 跟进线索id查询线索跟进记录列表
     *
     * @param clueId
     * @return
     */
    @Override
    public List<TbClueTrackRecord> selectTbClueTrackRecordList(Long clueId) {

        return tbClueTrackRecordMapper.selectTbClueTrackRecordList(clueId);
    }


    /**
     * 新增线索跟进功能
     *
     * @param tbClueTrackRecord
     * @return
     */
    @Override
    public Integer insertClueTrackRecordVo(ClueTrackRecordVo tbClueTrackRecord) {
        //0.拆分出线索表实体和线索跟进表实体
        TbClue tbClue=new TbClue();
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setId(tbClueTrackRecord.getClueId());//设置id
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());//跟进中

        TbClueTrackRecord tbClueTrackRecord1 = new TbClueTrackRecord();
        //copy属性
        BeanUtils.copyProperties(tbClueTrackRecord,tbClueTrackRecord1);
        //获取创建人
        tbClueTrackRecord1.setCreateTime(DateUtils.getNowDate());//修改现在时间
        tbClueTrackRecord1.setCreateBy(tbClueTrackRecord.getName());
        //1.修改线索表tb_clue
        clueMapper.updateTbClue(tbClue);
        //2.新增线索跟进表tb_clue_track_record
        return tbClueTrackRecordMapper.insertClueTrackRecordVo(tbClueTrackRecord1);
    }
}
